<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link rel="stylesheet" href="/static/base/common/css/sapar.css"/>
    <link rel="stylesheet" href="/static/base/static/css/index_inner.css"/>
    <link rel="stylesheet" type="text/css" href="/static/webjars/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" type="text/css" href="/static/webjars/layui/css/modules/layer/default/layer.css" media="all">
    <title>居民与房屋管理-修改户主信息</title>

    <style type="text/css">
        .table-backcolor {
            background-color: #eff6fa;
        }
        /*table tr td {*/
        /*text-align: center;*/
        /*}*/

        .red{
            border: 1px red solid;
        }

    </style>
</head>

<body>
<div id="container" >
    <div id="bd" style="width: 98%;height:100%;margin: 0 auto">
        <div id="test" >
            <form class="layui-form" action="" style="margin-top: 20px;" lay-filter="Proprietor">
                <div class="layui-collapse" lay-filter="test">
                    <div class="layui-colla-item">
                        <h2 class="layui-colla-title">户主信息</h2>
                        <div class="layui-colla-content layui-show">
                            <table class="layui-table">
                                <tr>
                                    <td width="150px">户主姓名</td>
                                    <td>
                                        <div class="layui-inline">
                                            <input type="text" name="name"  autocomplete="off" placeholder="请输入户主姓名" class="layui-input">
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>性别</td>
                                    <td>
                                        <div class="layui-inline">
                                            <input type="radio"  name="sex" lay-skin="primary" value="0" title="男">
                                            <input type="radio" name="sex" lay-skin="primary" value="1" checked title="女">
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>联系电话</td>
                                    <td>
                                        <div class="layui-inline">
                                            <input type="text" name="tellphone"  autocomplete="off" placeholder="请输入联系电话"  class="layui-input">
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>身份证号</td>
                                    <td>
                                        <div class="layui-inline">
                                            <input type="text" name="idCard"  autocomplete="off" placeholder="请输入户主身份证号" class="layui-input">
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>政治面貌</td>
                                    <td>
                                        <div class="layui-inline">
                                            <select name="politicalOutlook" id="politicalOutlook" lay-filter="politicalOutlook"></select>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td >家庭住址</td>
                                    <td >
                                        <div class="layui-input-inline">
                                            <select name="province" disabled>
                                                <option value="51" selected >四川省</option>
                                            </select>
                                        </div>
                                        <div class="layui-input-inline">
                                            <select name="city" disabled>
                                                <option value="5115" selected>宜宾市</option>
                                            </select>
                                        </div>
                                        <div class="layui-input-inline">
                                            <select name="county" disabled>
                                                <option value="511528" selected>兴文县</option>
                                            </select>
                                        </div>
                                        <div class="layui-input-inline">
                                            <select name="townId" id="townId" lay-filter="townId"></select>
                                        </div>
                                        <div class="layui-input-inline">
                                            <select name="villageId" id="villageId" lay-filter="villageId"></select>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>详细地址</td>
                                    <td>
                                        <div class="layui-inline">
                                            <input type="text" name="livein"  autocomplete="off" placeholder="请输入详细地址" class="layui-input">
                                        </div>
                                    </td>
                                </tr>



                                <tr>
                                    <td>月收入(元):</td>
                                    <td>
                                        <div class="layui-inline">
                                            <input type="text" name="income"  autocomplete="off" class="layui-input">
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>出生日期</td>
                                    <td>
                                        <div class="layui-inline">
                                            <input type="text" id="born" name="born" autocomplete="off" placeholder="yyyy-MM-dd" class="layui-input">
                                        </div>
                                    </td>

                                </tr>
                                <tr>
                                    <td>民族</td>
                                    <td>
                                        <div class="layui-inline">
                                            <select name="nation" id="nation" lay-filter="nation"></select>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>就业状况</td>
                                    <td>
                                        <div class="layui-inline">
                                            <select name="work">
                                                <option value="0" >待业</option>
                                                <option value="1" >就业</option>
                                                <option value="2" >创业</option>
                                            </select>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>工作行业</td>
                                    <td>
                                        <div class="layui-inline">
                                            <select name="industry" id="industry" lay-filter="industry"></select>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>婚姻状况</td>
                                    <td>
                                        <div class="layui-inline">
                                            <select name="marriage">
                                                <option value="未婚" >未婚</option>
                                                <option value="已婚" selected>已婚</option>
                                                <option value="离婚" >离婚</option>
                                                <option value="丧偶" >丧偶</option>
                                            </select>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>户口性质</td>
                                    <td>
                                        <div class="layui-inline">
                                            <select name="nohRegister">
                                                <option value="农业户口">农业户口</option>
                                                <option value="非农业户口" >非农业户口</option>
                                            </select>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>户籍所在地</td>
                                    <td>
                                        <div class="layui-inline">
                                            <input type="text" name="hrResiter"  autocomplete="off" class="layui-input">
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>受教育程度</td>
                                    <td>
                                        <div class="layui-input-inline">
                                            <select name="education">
                                                <option value="小学" selected >小学</option>
                                                <option value="初中" >初中</option>
                                                <option value="高中" >高中</option>
                                                <option value="专科" >专科</option>
                                                <option value="本科" >本科</option>
                                                <option value="硕士" >硕士</option>
                                                <option value="博士及以上" >博士及以上</option>
                                            </select>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>毕业学校</td>
                                    <td>
                                        <div class="layui-inline">
                                            <input type="text" name="school"  autocomplete="off" class="layui-input">
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>专业</td>
                                    <td>
                                        <div class="layui-inline">
                                            <input type="text" name="major"  autocomplete="off" class="layui-input">
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>健康状况</td>
                                    <td>
                                        <div class="layui-input-inline">
                                            <select name="healthStatus">
                                                <option value="1" selected >健康</option>
                                                <option value="2" >长期慢性病</option>
                                                <option value="3" >患大病</option>
                                            </select>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>是否低保户</td>
                                    <td>
                                        <div class="layui-inline">
                                            <input type="radio" checked name="isDb" lay-skin="primary" value="1" title="是">
                                            <input type="radio" name="isDb" lay-skin="primary" value="0" title="否">
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>是否已经购买保险</td>
                                    <td>
                                        <div class="layui-inline">
                                            <input type="radio" checked name="isBx" lay-skin="primary" value="1" title="是">
                                            <input type="radio" name="isBx" lay-skin="primary" value="0" title="否">
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>是否五保户</td>
                                    <td>
                                        <div class="layui-inline">
                                            <input type="radio" checked name="isWb" lay-skin="primary" value="1" title="是">
                                            <input type="radio" name="isWb" lay-skin="primary" value="0" title="否">
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>是否残疾</td>
                                    <td>
                                        <div class="layui-inline">
                                            <input type="radio" checked name="isCj" lay-skin="primary" value="1" title="是">
                                            <input type="radio" name="isCj" lay-skin="primary" value="0" title="否">
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>是否具有劳动力</td>
                                    <td>
                                        <div class="layui-inline">
                                            <input type="radio" checked name="isLdl" lay-skin="primary" value="1" title="是">
                                            <input type="radio" name="isLdl" lay-skin="primary" value="0" title="否">
                                        </div>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" style="width: 98%;margin: 20px auto">
                    <div class="layui-input-block">
                        <button class="layui-btn " lay-submit="" lay-filter="demo1">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>

</body>
<script type="text/javascript" src="/static/webjars/layui/layui.all.js"></script>
<script type="text/javascript" src="/static/base/common/js/jquery.js"></script>
<script type="text/javascript" src="/static/base/common/js/sapar.js"></script>
<script type="text/javascript" src="/static/base/static/js/index_inner.js"></script>
<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate
            ,$ = layui.$;

        //日期
        laydate.render({
            elem: '#born'
        });

        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');


        function checkNotNull(){
            var flag = true;
            $("input[type='text']").each(function(){

                if ("" == $(this).val()) { //判断元素对象的value值
                    $(this).addClass("red"); //添加css样式
                    flag = false;
                }else{
                    $(this).removeClass("red");
                }
                var divBox = $(this).parent().parent().parent().parent().parent().parent();
                if($(this).attr("class") =="layui-input red" && divBox.attr("class") != "layui-colla-content layui-show"){
                    divBox.addClass("layui-show")
                }

            });
            return flag;
        }


        //监听提交
        form.on('submit(demo1)', function(data){
            var flag= true;//判断是否数据格式都填写正确
            console.log(flag);
            if(!checkNotNull()){
                layer.msg('还有未填写的地方哦',{time:2000, shift: 6, icon:5},function(){});
                flag = false;
            }else {
                flag = true;
            }

            if(flag){
                // data.field.name = $("input[name='name']").val();
                // data.field.idCard = $("input[name='idCard']").val();
                // data.field.houseNum = $("input[name='houseNum']").val();
                // data.field.cardNum = $("input[name='cardNum']").val();
                // data.field.houseWarrant = $("input[name='houseWarrant']").val();
                // data.field.time = $("input[name='time']").val();
                // data.field.buildName = $("input[name='buildName']").val();
                // data.field.buildTime = $("input[name='buildTime']").val();
                // data.field.tubeUnit = $("input[name='tubeUnit']").val();
                // data.field.time = $("input[name='time']").val();
                // data.field.area = $("input[name='area']").val();
                // data.field.structure = $("input[name='structure']").val();
                // data.field.structure = $("input[name='structure']").val();
                // data.field.structure = $("input[name='structure']").val();
                // data.field.structure = $("input[name='structure']").val();
                // data.field.createTime = ("" + nowtimestamp).trim();
                // data.field.content = layedit.getContent(editIndex);
                // data.field.eventTypeBig = $("#eventTypeBig option:selected").text();
                // data.field.eventTypeTwo = $("#eventTypeTwo option:selected").text();
                // data.field.province = $("#province option:selected").text();
                // data.field.city = $("#city option:selected").text();
                // data.field.county = $("#county option:selected").text();
                // data.field.eventSrcname = "网上举报";
                // data.field.eventNature = "一般案件";
                var birthday=new Date($("#born").val().replace(/-/g, "\/"));
                var d=new Date();
                var age = d.getFullYear()-birthday.getFullYear()-((d.getMonth()<birthday.getMonth()|| d.getMonth()==birthday.getMonth() && d.getDate()<birthday.getDate())?1:0);
                data.field.age = age;
                data.field.id = GetRequest();
                data.field.updateTime = (new Date().getTime())/1000;

                console.log(data.field);
                $.ajax({
                    url: '/ajax/house/userInfo/pubuser',
                    type: 'POST',
                    contentType : 'application/json;charset=utf-8',
                    //设置请求头信息
                    dataType:"json",
                    data: JSON.stringify(data.field),
                    success: function(data){
                        layer.msg(data.code);
                        nowtimestamp = (new Date()).getTime();
                    },
                    error: function(res){
                        layer.msg(res);
                    }
                });

            }
            return false;
        });


        $.ajax({ //jquery跳转传输数据
            type : "POST",
            url : "/ajax/house/userInfo/seachByUserIdOrigin",//跳转的controller
            dataType : "json",//返回类型
            contentType : "application/x-www-form-urlencoded; charset=utf-8",
            data : {//传输controller的键值对
                "id" : GetRequest()
            },
            success : function(house) {//成功后执行并取值

                form.val('Proprietor', {
                    "name": house.data.name  // "name": "value"
                    ,"idCard": house.data.idCard
                    ,"sex": house.data.sex
                    ,"age": house.data.age
                    ,"politicalOutlook": ""+house.data.politicalOutlook
                    ,"tellphone": house.data.tellphone
                    ,"livein": house.data.livein
                    ,"nation": ""+house.data.nation
                    ,"work": house.data.work
                    ,"industry": house.data.industry
                    ,"marriage": house.data.marriage
                    ,"nohRegister": house.data.nohRegister
                    ,"hrResiter": house.data.hrResiter
                    ,"education": house.data.education
                    ,"income": house.data.income
                    ,"school": house.data.school
                    ,"born": house.data.born
                    ,"major": house.data.major
                    ,"isDb": ""+house.data.isDb
                    ,"isBx": ""+house.data.isBx
                    ,"isWb": ""+house.data.isWb
                    ,"isCj": ""+house.data.isCj
                    ,"isLdl": ""+house.data.isLdl
                    ,"healthStatus": ""+house.data.healthStatus
                })


            },
            error : function(request) {//失败后执行
                layer.msg("数据加载失败");
            }
        });

        function GetRequest() {
            var url = location.search; //获取url中"?"符后的字串
            if (url.indexOf("?") != -1) {    //判断是否有参数
                var str = url.substr(1); //从第一个字符开始 因为第0个是?号 获取所有除问号的所有符串
                strs = str.split("=");   //用等号进行分隔 （因为知道只有一个参数 所以直接用等号进分隔 如果有多个参数 要用&号分隔 再用等号进行分隔）
                return strs[1];          //直接弹出第一个参数 （如果有多个参数 还要进行循环的）
            }
        }


        var check;
        $.post("/ajax/pub/gettown",{code: "511528"},
            function (result) {
                //输出
                //执行清空
                $("#townId").empty();
                $("#villageId").empty();
                for(i = 0; i < result.length; i++){
                    document.getElementById("townId").options.add(new Option(result[i].townName,result[i].townId));
                }
                form.render();


                setInterval(function(){
                    if(check == undefined){
                        check = $('#townId').val();
                        $.post("/ajax/pub/getvillage",{code: check},
                            function (result) {
                                //输出
                                //执行清空
                                $("#villageId").empty();
                                for(i = 0; i < result.length; i++){
                                    document.getElementById("villageId").options.add(new Option(result[i].villageName,result[i].villageId));
                                }
                                form.render();
                            }
                        );
                    }else if(check != ($('#townId').val())){
                        check = $('#townId').val();
                        $.post("/ajax/pub/getvillage",{code: check},
                            function (result) {
                                //输出
                                //执行清空
                                $("#villageId").empty();
                                for(i = 0; i < result.length; i++){
                                    document.getElementById("villageId").options.add(new Option(result[i].villageName,result[i].villageId));
                                }
                                form.render();
                            }
                        );
                    }
                },500);
            }
        );

        $.post("/ajax/house/userInfo/getNationClass",
            function (result) {
                //输出
                //执行清空
                $("#nation").empty();
                for(i = 0; i < result.length; i++){
                    document.getElementById("nation").options.add(new Option(result[i].name,result[i].id));
                }
                form.render();

            }
        );

        $.post("/ajax/house/userInfo/getIndustryClass",
            function (result) {
                //输出
                //执行清空
                $("#industry").empty();
                for(i = 0; i < result.length; i++){
                    document.getElementById("industry").options.add(new Option(result[i].name,result[i].id));
                }
                form.render();

            }
        );

        $.post("/ajax/house/userInfo/getPoliticalOutlookClass",
            function (result) {
                //输出
                //执行清空
                $("#politicalOutlook").empty();
                for(i = 0; i < result.length; i++){
                    document.getElementById("politicalOutlook").options.add(new Option(result[i].name,result[i].id));
                }
                form.render();

            }
        );



    });
</script>

</html>
